package com.web44.ssm.config;

import com.github.pagehelper.PageInterceptor;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @Title: MyBatisConfig
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/2/18 9:28
 */
public class MyBatisConfig {

    /**
     * 主配置文件  相当于sqlMapperConfig.xml
     * @param dataSource
     * @return
     */
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource,PageInterceptor pageInterceptor) {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setPlugins(pageInterceptor);
        sqlSessionFactoryBean.setTypeAliasesPackage("com.web44.ssm.bean");
        return sqlSessionFactoryBean;

    }

    /**
     * 配置mapper扫描
     * @return
     */
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.web44.ssm.mapper");
        return msc;
    }
    @Bean
    public PageInterceptor pageInterceptor() {
        PageInterceptor pageInterceptor = new PageInterceptor();
        return pageInterceptor;
    }


}
